/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.practica.dao;

import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import edu.practica.model.Bus;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author Algo
 */
@Stateless
public class Bus1DAO {
@PersistenceContext
    private EntityManager entityManager;


    @PostConstruct
    public void init() {
        System.out.println("entityManager: "+entityManager);
    }
    

    public void registrar(Bus dus) {
        System.out.println("BusDAO.registar:" + dus);
        entityManager.persist(dus);
    }
    
    public void eliminar(Bus dus) {
        System.out.println("Zaona_BarrioDAO.eliminar:" + dus);
        dus = entityManager.getReference(Bus.class, dus.getId());
        entityManager.remove(dus);
    }
    
    public void modificar(Bus dus) {
        System.out.println("ProductoDAO.modificar:" + dus);
        entityManager.merge(dus);
    }
    
    public Bus findByID(Integer id) {
        return entityManager.find(Bus.class, id);
    }
    

    public List<Bus> listBus() {
        List<Bus> list = null;
        
        TypedQuery<Bus> query = 
                entityManager.createQuery("SELECT p FROM Bus p", Bus.class);
        list = query.getResultList();
        
        return list;
    }
    
    public EntityManager getEntityManager() {
        return entityManager;
    }

    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    
    
}
